<html>
<head>
</head>
<body bgcolor="#FFFFFF">
<h2>1 Introduction</h2>
<p class="Body">Traditionally bitmaps in Graphics32 have been using resources managed by the Windows GDI. While this is feasible for most usage scenarios in Windows there are some that require certain less resource-restricted approaches like handle-less bitmaps or bitmaps that rely on memory-mapped files. Prior to Graphics32 1.9 several community-driven patches existed that added these features.<br>
With the arrival of broader platform support in Graphics32 we are separating the memory management as well as OS or graphics subsystem specific methods from the generic methods in <a href="../Units/GR32/Classes/TBitmap32/_Body.htm">TBitmap32</a> and move these portions into so called back-end classes.</p>
<h2>2 Approach and compatibility</h2>
<p class="Body">In order to keep backwards compatibility the <a href="../Units/GR32/Classes/TBitmap32/_Body.htm">TBitmap32</a> class still exposes the same external interface. In order to get a clean cut from the platform specific methods and properties we implemented a new in-between class <a href="../Units/GR32/Classes/TCustomBitmap32/_Body.htm">TCustomBitmap32</a> which is truly platform agnostic and relies solely on the associated back-end class to handle its needs. As a matter of fact <a href="../Units/GR32/Classes/TCustomBitmap32/_Body.htm">TCustomBitmap32</a> is missing all Text, Canvas and Handle methods. Back-ends may implement predefined interfaces to implement the functionality.</p>
<p class="Body">The back-end instance is switchable during the lifecycle of a <a href="../Units/GR32/Classes/TCustomBitmap32/_Body.htm">TCustomBitmap32</a> instance. Conversion to the new back-end instance is handled transparently, i.e. without loosing the bitmap's surface contents. For instance this allows for temporarily switching a handle-less memory-only bitmap to a GDI bitmap with handle and vice versa. <a href="../Units/GR32/Classes/TCustomBitmap32/_Body.htm">TCustomBitmap32</a> exposes the current back-end via its <a href="../Units/GR32/Classes/TCustomBitmap32/Properties/Backend.htm">Backend</a> property. <br><br>

<div class="pseudoTbl">
<div><b>Code example (Switching back-ends)</b></div>
<pre class="brush: delphi;">begin
  MyBitmap := TBitmap32.Create;
  // Switch to a handle-less memory mapped file back-end...
  TMMFBackend.Create(MyBitmap); 
  MyBitmap.SetSize(5000, 5000);

  // Draw onto your new big bitmap...
  // Note: No text or canvas drawing is allowed because 
  // TMMFBackend does not implement those operations.
  // Use TGDIMMFBackend instead...

  // Switch to a GDI back-end and convert the current buffer...
  TGDIBackend.Create(MyBitmap); 
  MyBitmap.SaveToFile('test.bmp');
end;</pre></div>
</p>

<h2>3 Class and interface overview</h2>
<p class="Body">Currently Graphics32 ships with the following back-end classes which are subclasses of <a href="../Units/GR32/Classes/TBackend/_Body.htm">TBackend</a> and implement several interfaces (see below):</p>
<ul>
  <li><strong>Generic back-ends</strong>
    <ul>
      <li><a href="../Units/GR32_Backends_Generic/Classes/TMemoryBackend/_Body.htm">TMemoryBackend</a> (default for <a href="../Units/GR32/Classes/TCustomBitmap32/_Body.htm">TCustomBitmap32</a>) </li>
      <li><a href="../Units/GR32_Backends_Generic/Classes/TMMFBackend/_Body.htm">TMMFBackend</a></li>
    </ul>
  </li>
  <li><strong class="Body">Windows GDI/VCL back-ends </strong>
    <ul>
      <li><a href="../Units/GR32_Backends_VCL/Classes/TGDIBackend/_Body.htm">TGDIBackend</a> (default for <a href="../Units/GR32/Classes/TBitmap32/_Body.htm">TBitmap32</a>) </li>
      <li><a href="../Units/GR32_Backends_VCL/Classes/TGDIMMFBackend/_Body.htm">TGDIMMFBackend</a></li>
      <li><a href="../Units/GR32_Backends_VCL/Classes/TGDIMemoryBackend/_Body.htm">TGDIMemoryBackend</a></li>
    </ul>
  </li>
  <li><strong>Lazarus back-ends (currently Windows, OS X Carbon, GTK)</strong>
    <ul>
      <li>TLCLBackend (default for <a href="../Units/GR32/Classes/TBitmap32/_Body.htm">TBitmap32</a>)</li>
      <li>TLCLMMFBackend (Windows only) </li>
</ul>
  </li>
</ul>
<p class="Body">By default <a href="../Units/GR32/Classes/TBitmap32/_Body.htm">TBitmap32</a> now uses the back-end class TGDIBackend on Delphi/VCL/Windows and TLCLBackend on FreePascal/LCL/[supported OS (see above)].</p>
<p class="Body">Each of these back-ends may or may not implement certain pre-defined interfaces which can be queried for at runtime either directly via the back-end or indirectly via the bitmap instance:</p>
<ul>
  <li><a href="../Units/GR32_Backends/Interfaces/IPaintSupport/_Body.htm">IPaintSupport</a></li>
  <li><a href="../Units/GR32_Backends/Interfaces/ICopyFromBitmapSupport/_Body.htm">ICopyFromBitmapSupport</a></li>
  <li><a href="../Units/GR32_Backends/Interfaces/IBitmapContextSupport/_Body.htm">IBitmapContextSupport</a></li>
  <li><a href="../Units/GR32_Backends/Interfaces/IDeviceContextSupport/_Body.htm">IDeviceContextSupport</a></li>
  <li><a href="../Units/GR32_Backends/Interfaces/ITextSupport/_Body.htm">ITextSupport</a></li>
  <li><a href="../Units/GR32_Backends/Interfaces/IFontSupport/_Body.htm">IFontSupport</a></li>
  <li><a href="../Units/GR32_Backends/Interfaces/ICanvasSupport/_Body.htm">ICanvasSupport</a></li>
</ul>
<p class="Body"><strong>Please note:</strong> Most of the methods and properties left in <a href="../Units/GR32/Classes/TBitmap32/_Body.htm">TBitmap32</a> query the back-end for these specific interfaces. Failing to implement the required interfaces in the back-end class will cause  the method call or property read to fail with an exception. We recommend to change your custom routines or methods to use <a href="../Units/GR32/Classes/TCustomBitmap32/_Body.htm">TCustomBitmap32</a> instead of <a href="../Units/GR32/Classes/TBitmap32/_Body.htm">TBitmap32</a> wherever possible.</p>
<p>&nbsp;</p>
<p id="Hidden">[See Also] </p>
</body>
</html>
